#!/bin/bash
 
#============== Though ssh remote server ,auto modify ROOT passwd =============# 

for IP in `cat /root/ip_list.txt` #导入远程要修改主机的IP 
 
do 

#========================= 创建远程主机密码 ==========================#
 
TMP_PWD=`mkpasswd -l 8 -C 3`
 
R_PWD=`echo ${IP}_${TMP_PWD}`
 
echo "${IP}_${TMP_PWD}" > R_PWD.txt
 
 
 
#=========================== 修改远程主机密码 ========================#
 

if [ $? = 0 ] ; then
 
   ssh $IP passwd root --stdin < R_PWD.txt
 
   echo -e "$(date "+%Y-%m-%d %H:%M:%S")\t${IP}\t${R_PWD}\t" >> R_Server.log
 
else
 
   echo -e "$(date "+%Y-%m-%d %H:%M:%S")\t${IP} R_PWD.txt is create fail\tplease check!\t" >> M_pass.log
 
fi
 
if [ $? = 0 ] ; then
 
   echo -e "$(date "+%Y-%m-%d %H:%M:%S")\tThe ${IP} passwd is modify OK\t" >> M_pass.log
 
else
 
   echo -e "$(date "+%Y-%m-%d %H:%M:%S")\tThe ${IP} passwd is modify fail\tplease check!\t" >> M_pass.log
 
fi
 
done
